<?php

class Registry {

    private static $oInstance;
    private $aStack;

    public static function getInstance() {

        if(!isset(self::$oInstance)) {
            self::$oInstance = new Registry();
        }

        return self::$oInstance;

    }

    private function Registry() {

        $this->aStack = array(array());
    }

    public function set($sKey, &$mItem) {

        $this->aStack[0][$sKey] =& $mItem;

    }

    public function &get($sKey) {

        return $this->aStack[0][$sKey];

    }

    public function has($sKey) {

        return isset($this->aStack[0][$sKey]);

    }

    public function save() {

        array_unshift($this->aStack, array());

    }

    public function restore() {

        array_shift($this->aStack);

    }

    public function reset() {

        self::$oInstance = null;

    }

}

?>